# 计算最大公约数
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


# 输入第一个分数
num1 = int(input())
den1 = int(input())
# 输入运算符
operator = int(input())
# 输入第二个分数
num2 = int(input())
den2 = int(input())

if operator == 1:  # 加法
    result_num = num1 * den2 + num2 * den1
    result_den = den1 * den2
elif operator == 2:  # 减法
    result_num = num1 * den2 - num2 * den1
    result_den = den1 * den2
elif operator == 3:  # 乘法
    result_num = num1 * num2
    result_den = den1 * den2
elif operator == 4:  # 除法
    result_num = num1 * den2
    result_den = den1 * num2
else:
    print("无效的运算符")

# 处理结果为0的情况
if result_num == 0:
    result_den = 1
else:
    # 约分
    divisor = gcd(abs(result_num), abs(result_den))
    result_num //= divisor
    result_den //= divisor

print(result_num)
print(result_den)